<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "carousel".
 *
 * @property integer $carousel_id
 * @property string $image
 * @property string $link
 * @property string $title
 * @property string $text
 * @property integer $order_num
 * @property integer $status
 */



class Carousel extends \yii\db\ActiveRecord
{
    public $file;

    const PHOTO_PATH = 'carousel/photo';
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'carousel';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['image'], 'required'],
            [['text'], 'string'],
            [['order_num', 'status'], 'integer'],
            [['image', 'title'], 'string', 'max' => 128],
            [['link'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'carousel_id' => '轮播图编号',
            'image' => '轮播大图',
            'link' => '链接',
            'title' => '标题',
            'text' => '描述文本',
            'order_num' => '序号',
            'status' => '状态',
            'file' => '轮播图片文件',
        ];
    }

    //轮播图显示隐藏状态 
    static function getStatusOption($key=null)
    {
        $arr = array(
            1 => '显示',
            2 => '隐藏',
        );        
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    static function getStatus($model)
    {
        return self::getStatusOption($model->status);
    }

    static function getViewCarouselPic($model)
    {
        if(!empty($model->image))
            $imgHtml = '<img src=' . $model->image . ' width=480>';
        else 
            $imgHtml ='';

        return $imgHtml;
    }



}
